<template>
  <div>
    <el-menu
      :default-active="activeIndex2"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
    >
      <el-menu-item index="1">导航栏</el-menu-item>
      <el-dropdown class="ml-auto" @command="handlerAvatar">
        <el-button type="text" class="p-0">
          <div class="block">
            <el-avatar :size="50" :src="circleUrl" icon="el-icon-user-solid"></el-avatar>
          </div>
      </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>修改密码</el-dropdown-item>
          <el-dropdown-item :command="logout">退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: "Top",
  data() {
    return {
      activeIndex: "1",
      activeIndex2: "1",
      circleUrl: "http://www.baidu.com",
    };
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    logout(){
      this.$store.dispatch('user/logout')
      this.$message.success("退出登录成功!")
      this.$router.push('/login')
    },
    // 处理头像菜单点击事件
    handlerAvatar(command){command()},
  },
};
</script>

<style scoped>
.ml-auto {
  float: right;
  padding: 0px;
}
.p-0{
  padding: 0;
  padding-top: 10px;
  padding-right: 20px;
}
</style>